#include "Pong.h"
#include "Messages.pb.h"
#include <unistd.h>

Pong::Pong():pub_(),sub_(),reader_(*this)
{
  fsk::msg::Message01 msg;
  sub_.registerHandler(msg,reader_);
}

Pong::~Pong()
{
  fsk::msg::Message02 m;
  sub_.unregisterHandler(m,reader_);
 
}

Pong::MsgReader::MsgReader(Pong& obj):obj_(obj)
{
}

void Pong::MsgReader::handle(fsk::msg::Message01& msg)
{
  //printf("(%s:%d) handling msg %d\n",__FILE__,__LINE__,msg.val01());
  obj_.sendResponse(msg);
}

void Pong::sendResponse(fsk::msg::Message01& msg)
{
  fsk::msg::Message02 response;
  response.set_val01(msg.val01());
  pub_.publish(response);
}
